package com.liuboya.weibomodel.model.base;

import com.liuboya.weibomodel.model.enums.DeleteEnum;
import lombok.Data;

import java.time.Instant;

@Data
public abstract class BaseEntity {

    /**
     * 创建时间
     */
    private Long created;

    /**
     * 更新时间
     */
    private Long updated;

    /**
     * 0 未删除 1已删除
     */
    private Integer isDeleted;

    /**
     * 备注字段
     */
    private String extra;


    public void checkBeforeInsert() {
        long now = Instant.now().getEpochSecond();
        if (null == this.created) {
            this.created = now;
        }
        if (null == this.updated) {
            this.updated = now;
        }
        this.isDeleted = DeleteEnum.DELETED_NOT.getVal();
    }

    public void checkBeforeUpdate() {
        long now = Instant.now().getEpochSecond();
        if (null == this.updated) {
            this.updated = now;
        }
    }

}
